home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / dev / gcc / ixemul_src.lha / ixemul-41.0 / library / ix_close.c < prev    next >
C/C++ Source or Header  |  1995-05-27  |  4KB  |  153 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  ix_close.c,v 1.1.1.1 1994/04/04 04:30:26 amiga Exp
  20.  *
  21.  *  ix_close.c,v
  22.  * Revision 1.1.1.1  1994/04/04  04:30:26  amiga
  23.  * Initial CVS check in.
  24.  *
  25.  *  Revision 1.7  1993/11/05  21:53:38  mw
  26.  *  close inet-library, if we opened it
  27.  *
  28.  *  Revision 1.6  1992/10/20  16:18:58  mwild
  29.  *  moved closing of files out before Forbid (ix_startup, vfork)
  30.  *  possibly free a4 databss-segment here (see ix_resident.c)
  31.  *
  32.  *  Revision 1.5  1992/08/09  20:46:42  amiga
  33.  *  delay restoring of old handlers
  34.  *
  35.  *  Revision 1.4  1992/07/04  19:12:12  mwild
  36.  *  don't just free death-messages, wake any children possibly waiting on them
  37.  *
  38.  * Revision 1.3  1992/05/22  01:44:17  mwild
  39.  * when debugging, check whether buddy allocator clean
  40.  *
  41.  * Revision 1.2  1992/05/18  12:18:00  mwild
  42.  * changed async mp to be global
  43.  *
  44.  * Revision 1.1  1992/05/14  19:55:40  mwild
  45.  * Initial revision
  46.  *
  47.  */
  48.  
  49. #define KERNEL
  50. #include "ixemul.h"
  51. #include "kprintf.h"
  52. #undef u
  53. #undef ix
  54. #include <hardware/intbits.h>
  55.  
  56. #define BASE_EXT_DECL
  57. #define BASE_EXT_DECL0
  58. #define BASE_PAR_DECL    struct ixemul_base *ix,
  59. #define BASE_PAR_DECL0    struct ixemul_base *ix
  60. #define BASE_NAME    ix->ix_intui_base
  61. #include <inline/intuition.h>
  62.  
  63. extern struct ExecBase     *SysBase;
  64.  
  65. extern int _do_net;
  66.  
  67. void
  68. ix_close (struct ixemul_base *ixbase)
  69. {
  70.   int fd;
  71.   struct Task         *me      =    SysBase->ThisTask;
  72.   struct user         *u     =    (struct user *) me->tc_TrapData;
  73.   struct Process    *child;
  74.   struct user        *cu;
  75.   struct Node        *dm, *ndm;    /* really struct death_msg * */
  76.  
  77.   RemIntServer (INTB_VERTB, & u->u_itimerint);
  78.   /* already reset the trap vector here. It's better to get an alert than
  79.    * to loop infinitely if one of the following functions should crash */
  80.   me->tc_TrapCode = u->u_otrap_code;
  81.  
  82.   /* had to move this block after the SYS_close's, since close() might have
  83.      to wait for a packet, and then it's essential that our switch/launch
  84.      handlers are still active, or curproc is not updated accordingly */
  85.   me->tc_Flags    = u->u_otask_flags;
  86.   me->tc_Launch      = u->u_olaunch;
  87.   me->tc_Switch   = u->u_oswitch;
  88.   FreeSignal (u->u_sleep_sig);
  89.   if (u->u_InetBase)
  90.     {
  91.       FreeSignal (u->u_sigurg);
  92.       FreeSignal (u->u_sigio);
  93.       CloseLibrary (u->u_InetBase);
  94.     }
  95.   CloseDevice ((struct IORequest *) u->u_time_req);
  96.   syscall (SYS_DeleteExtIO, u->u_time_req);
  97.   
  98.   if (u->u_startup_cd != (BPTR) -1) __unlock (CurrentDir (u->u_startup_cd));
  99.  
  100.   u->u_trace_flags = 1;
  101.   DeletePort (u->u_sync_mp);
  102.  
  103. #if 0
  104.   /* see ix_open.c */
  105.   DeleteInterruptPort (u->u_async_mp);
  106. #endif
  107.  
  108. #if 0
  109.   /* can't do this here, we're inside Forbid and if ix_lock_base would block,
  110.      the Forbid would be broken */
  111.  
  112.   /* have to make sure that no child is trying to manipulate our process
  113.    * lists as well */
  114.   ix_lock_base ();
  115. #endif
  116.  
  117.   for ((child = u->p_cptr) && (cu = (struct user *) (child->pr_Task.tc_TrapData));
  118.        child;
  119.        (child = cu->p_osptr) && (cu = (struct user *) (child->pr_Task.tc_TrapData)))
  120.     cu->p_pptr = (struct Process *) 1;
  121.  
  122.   u->p_cptr = 0;
  123.   
  124.   for (dm  = (struct Node *) u->p_zombies.mlh_Head;
  125.        ndm = dm->ln_Succ;
  126.        dm  = ndm)
  127.     {
  128.       /* there might be children sleeping on this, so wake them up now.. */
  129.       ix_wakeup (dm);
  130.       kfree (dm);
  131.     }
  132.  
  133. #if 0
  134.   ix_unlock_base ();
  135. #endif
  136.  
  137.   FreeSignal (u->p_zombie_sig);
  138.  
  139.   all_free ();
  140.   if (u->p_flag & SFREEA4)
  141.     kfree (u->u_a4 - 0x7ffe);
  142.  
  143. #ifdef DEBUG
  144. /*  check_empty (0);*/
  145. #endif
  146.  
  147.   /* delay this until here, since the above called functions need access
  148.    * to the user area. */
  149.   me->tc_TrapData = u->u_otrap_data;
  150.  
  151.   kfree (u);
  152. }
  153.